﻿using Microsoft.Phone.Controls;
using System;
using System.Windows.Navigation;

namespace KouDai.Phone.Common
{
    public class PhoneAwarePage : PhoneApplicationPage
    {
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            if (e.NavigationMode == NavigationMode.Back)
            {
                ReLoadData();
            }
            else
            {
                InitData();
            }
            base.OnNavigatedTo(e);
        }


        protected override void OnNavigatedFrom(NavigationEventArgs e)
        {
            base.OnNavigatedFrom(e);
            if (e.NavigationMode != NavigationMode.Back)
            {
                SaveData();
            }
            else
            {
                ClearData();
            }
        }

        #region Override DataOperate

        /// <summary>
        /// 第一次加载数据
        /// </summary>
        protected virtual void InitData()
        {

        }

        /// <summary>
        /// 进入墓碑时重新加载数据
        /// </summary>
        protected virtual void ReLoadData()
        {
            
        }

        /// <summary>
        /// 保存数据
        /// </summary>
        protected virtual void SaveData()
        {
            
        }

        /// <summary>
        /// 清楚数据
        /// </summary>
        protected virtual void ClearData()
        {
            
        }

        #endregion
    }
}
